home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / exec / attemptsemaphoreshared.c < prev    next >
C/C++ Source or Header  |  1996-09-12  |  2KB  |  86 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: attemptsemaphoreshared.c,v 1.4 1996/08/13 13:55:58 digulla Exp $
  4.     $Log: attemptsemaphoreshared.c,v $
  5.     Revision 1.4  1996/08/13 13:55:58  digulla
  6.     Replaced __AROS_LA by __AROS_LHA
  7.     Replaced some __AROS_LH*I by __AROS_LH*
  8.     Sorted and added includes
  9.  
  10.     Revision 1.3  1996/08/01 17:41:05  digulla
  11.     Added standard header for all files
  12.  
  13.     Desc:
  14.     Lang: english
  15. */
  16. #include "exec_intern.h"
  17. #include "semaphores.h"
  18.  
  19. /*****************************************************************************
  20.  
  21.     NAME */
  22.     #include <exec/semaphores.h>
  23.     #include <clib/exec_protos.h>
  24.  
  25.     __AROS_LH1(ULONG, AttemptSemaphoreShared,
  26.  
  27. /*  SYNOPSIS */
  28.     __AROS_LHA(struct SignalSemaphore *, sigSem, A0),
  29.  
  30. /*  LOCATION */
  31.     struct ExecBase *, SysBase, 120, Exec)
  32.  
  33. /*  FUNCTION
  34.     Tries to get a shared lock on a signal semaphore. If the lock cannot
  35.     be obtained false is returned. There may be more than one shared lock
  36.     at a time but an exclusive lock prevents all other locks. The lock
  37.     must be released with ReleaseSemaphore().
  38.  
  39.     INPUTS
  40.     sigSem - pointer to semaphore structure
  41.  
  42.     RESULT
  43.     True if the semaphore could be obtained, false otherwise.
  44.  
  45.     NOTES
  46.  
  47.     EXAMPLE
  48.  
  49.     BUGS
  50.  
  51.     SEE ALSO
  52.     ReleaseSemaphore()
  53.  
  54.     INTERNALS
  55.  
  56.     HISTORY
  57.     29-10-95    digulla automatically created from
  58.                 exec_lib.fd and clib/exec_protos.h
  59.  
  60. *****************************************************************************/
  61. {
  62.     __AROS_FUNC_INIT
  63.     __AROS_BASE_EXT_DECL(struct ExecBase *,SysBase)
  64.     LONG ret=0;
  65.  
  66.     /* Arbitrate for the semaphore structure */
  67.     Forbid();
  68.  
  69.     /*
  70.     If the semaphore is free, shared locked or owned by the current task
  71.     it's possible to get another lock.
  72.     */
  73.     if(sigSem->ss_NestCount<=0||sigSem->ss_Owner==SysBase->ThisTask)
  74.     {
  75.     /* Get it and return success */
  76.     ObtainSemaphoreShared(sigSem);
  77.     ret=1;
  78.     }
  79.  
  80.     /* All done. */
  81.     Permit();
  82.     return ret;
  83.     __AROS_FUNC_EXIT
  84. } /* AttemptSemaphoreShared */
  85.  
  86.